package com.studio.dao.impl;

import java.util.List;

import com.studio.base.dao.BaseDao;
import com.studio.base.utils.Pager;
import com.studio.dao.TablesDao;
import com.studio.entity.Tables;
import com.studio.entity.Users;

public class TablesDaoImpl extends BaseDao implements TablesDao {

	@Override
	public Pager find(Pager pager) {
		return findPageByCriteria(pager.getPageNo(), pager.getPageSize(), new Users());
	}

	@Override
	public Pager findAllTables(Pager pager) {
		return findPageByCriteria(pager.getPageNo(), pager.getPageSize(), new Tables());
	}

	@Override
	public List<?> findCanExportTables() {
		return this.getHibernateTemplate().find("from Tables where isAllow = 1");
	}

	@Override
	public void edit(Tables table) {
		this.getHibernateTemplate().update(table);
	}
	
	@Override
	public void del(Tables table) {
		this.getHibernateTemplate().delete(table);
	}

	@Override
	public boolean add(Tables table) {
		Integer i = (Integer)this.getHibernateTemplate().save(table);
		return i>0;
	}

	@Override
	public void delByIds(Integer[] ids) {
		for (Integer id : ids) {
			String hqlDelete = "delete Tables t where t.id = :id";
			getSession().createQuery( hqlDelete )
			.setInteger( "id", id )
			.executeUpdate();
		}
	}

}
